package com.gml.design.principle.lishitihuan.optimize;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.math.BigDecimal;

public class CreditCard extends CashCard{
    private Logger logger = LoggerFactory.getLogger(CreditCard.class);

    public CreditCard(String cardNo, String cardDate) {
        super(cardNo, cardDate);
    }

    @Override
    boolean rule(BigDecimal amount) {
        return amount.compareTo(new BigDecimal(1000)) > 0;
    }

    //付钱
    public String load(String orderId, BigDecimal amount){
        boolean rule = rule(amount);
        if (!rule){
            logger.info("生成贷款单失败，金额超限，单号：{} 金额：{}", orderId, amount);
            return "0001";
        }

        //模拟生成贷款单
        logger.info("生成贷款单，单号：{} 金额：{}", orderId, amount);
        //模拟支付成功
        logger.info("贷款成功， 单号：{} 金额：{}", orderId, amount);
        return super.negative(orderId,amount);
    }

    //信用卡还款
    public String repayMent(String orderId, BigDecimal amount){
        //模拟生成还款单
        logger.info("生成还款但，单号：{} 金额：{}", orderId, amount);
        //模拟还款成功
        logger.info("还款成功， 单号：{} 金额：{}", orderId, amount);
        return super.positive(orderId, amount);
    }
}
